package com.coder.bike.controller;

import com.coder.bike.service.IBalanceService;
import com.coder.bike.utils.Result;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/bike/balance")
public class BalanceController {

    private final IBalanceService balanceService;

    public BalanceController(IBalanceService balanceService) {
        this.balanceService = balanceService;
    }

    @PostMapping("/recharge")
    public Result rechargeBalance(
            @RequestParam Integer customerId,
            @RequestParam BigDecimal amount) {
        try {
            return balanceService.rechargeBalance(customerId, amount);
        } catch (Exception e) {
            return Result.fail().setMessage("充值失败: " + e.getMessage());
        }
    }

    @PostMapping("/payment-callback/{paymentNo}")
    public Result paymentCallback(@PathVariable String paymentNo) {
        try {
            return balanceService.handlePaymentSuccess(paymentNo);
        } catch (Exception e) {
            return Result.fail().setMessage("支付回调处理失败: " + e.getMessage());
        }
    }
}